<?php
namespace Admin\Controller;
use Think\Controller;
class ArticleClassController extends BackController {
	/**
	 * 初始化
	 */
	public function __construct() {
		parent::__construct();
	}

	/**
	 * 分类列表
	 */
    public function index() {
		$articleclass = D('article_class');
		$articleclass->mselect(); 
		$list = $articleclass->grade;
		$this->assign('list',$list);
		$this->display();
    }

	/**
	 * 添加、修改分类
	 */
	public function edit() {

		if(IS_POST) {
			$model = D('article_class');
			if(!$model->create()) {
				$this->error($model->getError());
				die();
			}
			$msg = $model->msave();
			if(!empty($msg)) {
				$this->success('操作成功！',U('ArticleClass/index'));
			} else {
				$this->error('操作失败！');
			}
			die();
		}
		
		$id = I('get.id','','intval');
		if(!empty($id)) {
			$info = D('article_class')->find($id);
			if(empty($info)) {
				die('not find this data');
			}
			$this->assign('info',$info);
		}

		$articleclass = D('article_class');
		$articleclass->mselect(); 
		$list = $articleclass->grade;
		$this->assign('list',$list);

		$this->display();
	}

	/**
	 * 删除
	 */
	public function del() {
		$id = I('get.id','','intval');
		if(!empty($id)) {
			$msg = D('article_class')->delete($id);
			if(empty($msg)) {
				$this->error('操作失败！',U('ArticleClass/index'));
			} else {
				$this->success('操作成功！',U('ArticleClass/index'));
			}
		}
	}

}
